package com.itinsys.enma.web;

import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itinsys.enma.domain.response.EnvironmentResponse;
import com.itinsys.enma.manager.EnvironmentManager;
import com.itinsys.enma.manager.ResponseManager;
import com.itinsys.enma.util.InitializationService;
/***
 * 
 * @author sperez
 * 
 */
@Controller
@RequestMapping(value = "/home")
public class HomeFormController extends FormController{

	protected final Log logger = LogFactory.getLog("controller");
	
	@Autowired
	private EnvironmentManager environmentManager;
	
	@Autowired
	private InitializationService initializationService;
	
	@Autowired
	private ResponseManager responseManager;

	
	@RequestMapping(method = RequestMethod.GET)
	protected void formBackingObject(HttpServletRequest request)
			throws ServletException {
	
	}
	
	
	@RequestMapping(value = "/environment/", method = RequestMethod.GET)
	@ResponseBody
	public EnvironmentResponse getAllEnvironment() {
		return environmentManager.getAllActiveEnvironment();
		
	}
	
	
	@RequestMapping(value = "/admin_services/initialize", method = RequestMethod.POST)
	public @ResponseBody Boolean environmentInitialize(HttpServletResponse response) {
		return initializationService.initialize();
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/environment/by_filter", method = RequestMethod.POST)
	public @ResponseBody EnvironmentResponse getEnvironmentByFilter(@RequestBody Object[] filterDTO, HttpServletResponse response) {
		return environmentManager.getEnvironmentByFilter((Map<String,Object>)filterDTO[0],(Integer)filterDTO[1],(String)filterDTO[2]);
	}
	
	
	
	
}
